//
//  ImageListCollectionViewCell.m
//  Castlery
//
//  Created by xie weizhi on 8/10/17.
//  Copyright © 2017 weizhi. All rights reserved.
//

#import "ImageListCollectionViewCell.h"

@implementation ImageListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self configureViews];
    }
    
    return self;
}

- (void)configureViews {
    _imageView = [UIImageView new];
    _imageView.translatesAutoresizingMaskIntoConstraints = NO;
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_imageView];
    
    [NSLayoutConstraint
     activateConstraints:@[[_imageView.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:5.f],
                           [_imageView.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-5.f],
                           [_imageView.leftAnchor constraintEqualToAnchor:self.contentView.leftAnchor constant:5.f],
                           [_imageView.rightAnchor constraintEqualToAnchor:self.contentView.rightAnchor constant:-5.f],]];
    
    [self setSelected:NO];
}

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    
    UIColor *borderColor = selected ? [UIColor blackColor] : [UIColor lightGrayColor];
    
    self.contentView.layer.borderWidth = 2.0f;
    self.contentView.layer.borderColor = borderColor.CGColor;
}

@end
